<template>
  <div :class="['message-box', type]">
    <div class="inner">
      <header class="header">
        <h1 class="title">{{ title }}</h1>
        <span @click="$messageBox.hide()">X</span>
      </header>
      <div class="content">{{ content }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MessageBox',
  props: {
    title: {
      type: String,
      default: 'This is TITLE'
    },
    content: {
      type: String,
      default: 'This is CONTENT'
    },
    type: {
      type: String,
      default: 'primary',
      validator(value) {
        return [
          'primary',
          'success',
          'warning',
          'danger'
        ].includes(value);
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  h1 {
    margin: 0;
    font-weight: normal;
  }
  .message-box {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);

    .inner {
      position: absolute;
      top: 100px;
      left: 50%;
      width: 500px;
      margin-left: -250px;
      background-color: #fff;
      box-shadow: 1px 3px 5px #ddd;
      border-radius: 5px;
      overflow: hidden;
      .header {
        padding: 0 10px;
        height: 44px;
        line-height: 44px;
        box-sizing: border-box;
        .title {
          float: left;
          font-size: 16px;
        }
        span {
          float: right;
          cursor: pointer;
        }
      }

      .content {
        padding: 20px;
        box-sizing: border-box;
      }
    }

    &.primary {
      .header {
        color: #fff;
        background-color: #409eff;
      }
    }
    &.success {
      .header {
        color: #fff;
        background-color: #67c23a;
      }
    }
    &.warning {
      .header {
        color: #333;
        background-color: #e6a23c;
      }
    }
    &.danger {
      .header {
        color: #fff;
        background-color: #f56c6c;
      }
    }
  }
</style>